//
//  GuideController.m
//  MyCloudMusic
//
//  Created by xiaolong on 2023/12/11.
//

#import "GuideController.h"
#import "Constant.h"
#import <QMUIKit/QMUIKit.h>
#import "ViewFactoryUtil.h"
#import "R.h"
#import <GKCycleScrollView/GKCycleScrollView.h>
#import <GKCycleScrollView/GKPageControl.h>

#import "UIColor+Config.h"
#import "UIColor+Hex.h"
#import "UIColor+Theme.h"
#import "SuperHttpUtil.h"

@interface GuideController ()<GKCycleScrollViewDataSource,GKCycleScrollViewDelegate>
@property(nonatomic, strong)GKCycleScrollView *contentScrollView;

@end

@implementation GuideController

- (void)initViews{
    [super initViews];
    
    [self initLinearLayoutSafeArea];
    [self setBackgroundColor: [UIColor whiteColor]];
    MyRelativeLayout *bannerVue = [MyRelativeLayout new];
    
    bannerVue.myHeight = MyLayoutSize.wrap;
    
    bannerVue.myWidth = MyLayoutSize.fill;
    bannerVue.weight = 1;
    
    [self.container addSubview:bannerVue];
    
    //bannerVue.backgroundColor = [UIColor redColor];
    _contentScrollView = [GKCycleScrollView new];
    _contentScrollView.backgroundColor = [UIColor clearColor];
    _contentScrollView.myHeight = MyLayoutSize.fill;
    _contentScrollView.myWidth = MyLayoutSize.fill;
    _contentScrollView.dataSource = self;
    _contentScrollView.delegate = self;
    
    //禁用自动滚动
    _contentScrollView.isAutoScroll=NO;
    
    //不改变透明度
    _contentScrollView.isChangeAlpha=NO;
    
    _contentScrollView.clipsToBounds = YES;
    
    [bannerVue addSubview:_contentScrollView];
    
    GKPageControl *pageControl = [GKPageControl new];
    pageControl.userInteractionEnabled = NO;
    pageControl.style = GKPageControlStyleCycle;
    _contentScrollView.pageControl = pageControl;
    pageControl.pageIndicatorTintColor = [UIColor black80];
    pageControl.currentPageIndicatorTintColor = [UIColor colorPrimary];
    pageControl.myWidth = MyLayoutSize.fill;
    pageControl.myHeight = 15;
    pageControl.myBottom = 40;
    [bannerVue addSubview:pageControl];
    
    
    MyLinearLayout *btnParentVue = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    
    btnParentVue.myHeight = MyLayoutSize.wrap;
    btnParentVue.myWidth = MyLayoutSize.fill;
    btnParentVue.myBottom = PADDING_LARGE2;
    
    btnParentVue.gravity = MyGravity_Horz_Among;
    
    [self.container addSubview:btnParentVue];
    
    QMUIButton *primaryBtn = [ViewFactoryUtil primaryButton];
    [primaryBtn setTitle:R.string.localizable.loginOrRegister forState:UIControlStateNormal];
    
    [primaryBtn addTarget:self action:@selector(loginOrRegisterClicked:) forControlEvents:UIControlEventTouchUpInside];
    primaryBtn.myWidth = BUTTON_WIDTH_MEDDLE;
    
    [btnParentVue addSubview:primaryBtn];
    
    
    QMUIButton *enterBtn = [ViewFactoryUtil primaryOutlineButton];
    [enterBtn setTitle:R.string.localizable.experienceNow forState:UIControlStateNormal];
    
    [enterBtn addTarget:self action:@selector(enterBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    enterBtn.myWidth = BUTTON_WIDTH_MEDDLE;
    
    [btnParentVue addSubview:enterBtn];
}

- (void)initDatum{
    [super initDatum];
    
    self.datum = [NSMutableArray array];
    
    [self.datum addObject:R.image.guide1];
    [self.datum addObject:R.image.guide2];
    [self.datum addObject:R.image.guide3];
    [self.datum addObject:R.image.guide4];
    [self.datum addObject:R.image.guide5];
    
    [_contentScrollView reloadData];
}

- (void)loginOrRegisterClicked:(QMUIButton *)btn{
    NSLog(@"xxx");
}


- (void)enterBtnClicked:(QMUIButton *)btn{
    NSLog(@"xxx");
    
    NSDictionary *dic = @{
        @"nikename":@"wanger"
    };
    
    NSDictionary *dicHeader = @{
        @"head":@"headarg"
    };
    
    NSString *url = @"v1/sheets";
    
    [MSNetwork HTTPWithMethod:MSRequestMethodGET url:url parameters:dic headers:dicHeader cachePolicy:MSCachePolicyOnlyNetNoCache success:^(id  _Nonnull responseObject) {
            NSLog(@"succ");
        } failure:^(NSError * _Nonnull error) {
            NSLog(@"failure");
        }];
    
}



#pragma mark --data sources
/// 返回cell个数
/// @param cycleScrollView cycleScrollView description
- (NSInteger)numberOfCellsInCycleScrollView:(GKCycleScrollView *)cycleScrollView{
    return self.datum.count;
}

/// 返回继承自GKCycleScrollViewCell的类
/// @param cycleScrollView cycleScrollView description
/// @param index 索引
- (GKCycleScrollViewCell *)cycleScrollView:(GKCycleScrollView *)cycleScrollView cellForViewAtIndex:(NSInteger)index{
    GKCycleScrollViewCell *cell = [cycleScrollView dequeueReusableCell];
    if(!cell){
        cell = [GKCycleScrollViewCell new];
    }
    UIImage *data = [self.datum objectAtIndex:index];
    cell.imageView.image = data;
    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    return cell;
}


@end

